<script>
$(document).ready(function(){

	$('#setForm').ajaxForm({
        success:       showResponse
        });
    function showResponse() {
        jAlert('<?php echo $this->translate("completed")?>');
    }


	$("#sortable tbody.content").sortable();
	$("#checkAll").click(function(){
	      $.each($("INPUT[@name='sn[]'][type='checkbox']"),function(){
	    	  $(this).attr('checked', !$(this).is(':checked'));
		  });
	 });
	 $(".new_student_id").bt({
		  trigger: ['focus', 'blur'],
		  positions: ['bottom']
		});

	 // 新增一列
	    $("#appendBtn").click(function(){
	        var number = parseInt($(".numbers:last").attr('value')) +1;

	        $("#sortable tbody").append('<tr><td></td>'+
	                '<td><input type="text" size="2" value="'+number+'" name="sn[]" class="numbers"></td>'+
	                '<td><input class="new_student_id" name="new_student_id" type="text" size="6" title="<?php echo $this->translate('append student memo')?>"/></td>'+
	                '<td></td><td></td><td></td><td></td><td></td></tr>');
	    });
	//$("#sortable tbody tr:even").addClass('even');
//	$("#sortable tbody tr:odd").addClass('odd');

});
</script>
<style>
#sortable {background:#ccc; margin:5px}
#sortable td{padding:3px; background: #ffe; text-align:center}
.sex-M {color:blue;}
.sex-F {color:#f55;}
</style>
<?php $studyCondition = Student_Model_Student::getStudentConditionArray()?>
<form id="setForm"  method="post" name="setForm" action="<?php echo $this->route('set')?>">
<input name="year_semester" id="hidden_year_semester" type="hidden"  value="<?php echo $this->year_semester?>"/>
<input name="classSn" id="hidden_classSn"  type="hidden"  value="<?php echo $this->classSn?>" />
<table id="sortable" >
<thead>
<tr>
<th></th>
<th><?php echo $this->translate('number')?></th>
<th><?php echo $this->translate('student id')?></th>
<th><?php echo $this->translate('student name')?></th>
<th><?php echo $this->translate('student sex')?></th>
<th><?php echo $this->translate('student condition')?></th>
</tr>
</thead>
<tbody class="content">
<?php foreach($this->data as $val):?>
<tr>
<td><span class="ui-icon ui-icon-arrowthick-2-n-s"></span></td>
<td>
<input class="numbers" type="text" name="sn[s<?php echo $val['sn']?>]" value="<?php echo $val['number']?>" size="2"/>
</td>
<td>
<?php if (isset($val['student_id'])):?>
<?php echo  $val['student_id']?>
<?php else:?>
<input type="text"  class="new_student_id" name="new_student_id[]" size="6"  title="<?php echo $this->translate('append student memo')?>"/>
<?php endif?>
</td>
<td class="sex-<?php echo $val['sex']?> student_name"><?php if (isset($val['name'])) echo $val['name']?>
</td>
<td class="sex-<?php echo $val['sex']?>">
<?php if (isset($val['sex'])=='M') echo $this->translate('boy'); elseif (isset($val['sex']) == 'F') echo $this->translate('girl')?></td>
<td><?php if (isset( $val['study_condition'])) echo $studyCondition[$val['study_condition']];?></td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</form>